package com.inspur.gs.sbssdl.sbwhgl.sbrh.sbrh.front.sbsslustand_frm.voactions;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.BeforeQueryAction;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;

import java.util.ArrayList;

public class beforeQueryVOAction extends BeforeQueryAction {

	public beforeQueryVOAction(QueryContext context){
		super(context);
	}
	@Override
	public void execute() {
		String mainName = (String) this.getContext().getVariableData().getValue("mainName");
		String className = (String) this.getContext().getVariableData().getValue("className");

		if (mainName != null && !mainName.isEmpty()){
			EntityFilter filter = getQueryContext().getFilter();
			if (className.equals("className") || className.isEmpty()){
				ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
						.andEqual("devClass", mainName)
						.build());
				filter.addFilterConditions(filterList);
			}else {
				ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
						.andEqual("devSpec", mainName)
						.andEqual("devClass", className)
						.build());
				filter.addFilterConditions(filterList);
			}
		}
	}
}
